<?php

namespace App\Library\Service;

use App\Library\Logic\AuctionCertificationLogic;
use App\Library\Logic\FollowLogic;
use App\Library\Logic\ShopUserLogic;
use App\Library\Requests\Base\BasePageRequest;
use App\Library\Requests\Base\IdRequest;
use Illuminate\Http\JsonResponse;

class FollowService extends BaseService
{
    /**
     * @param FollowLogic $logic
     */
    public function __construct(FollowLogic $logic)
    {
        $this->logic = $logic;
    }

    /**
     * add
     * @param IdRequest $request
     * @return JsonResponse
     *
     */
    public function addOrCancel(IdRequest $request): JsonResponse
    {
        $seller = AuctionCertificationLogic::existsByWhere([
            'status' => 1,
            'userId' => $request->id,
        ]);
        if ($seller === false) return failMessage('店铺不存在');
        $where = ['userId' => USERID, 'sellerId' => $request->id];
        if ($this->logic->existsByWhere($where)) $this->logic->deleteByWhere($where);
        else $this->logic->insert($where);
        return success();
    }

    /**
     * userPaging
     * @param BasePageRequest $request
     * @return JsonResponse
     */
    public function userPaging(BasePageRequest $request): JsonResponse
    {
        return success($this->logic->userPaging($request));
    }

    /**
     * sellerPaging
     * @param BasePageRequest $request
     * @return JsonResponse
     */
    public function sellerPaging(BasePageRequest $request): JsonResponse
    {
        return success($this->logic->sellerPaging($request));
    }
}
